﻿using Application.Users.GetById;
using Mediator;
using SharedKernel;
using WebApi.Extensions;
using WebApi.Infrastructure;

namespace WebApi.Endpoints.Users;

internal sealed class GetById : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("users/{userId}", async (
            Guid userId,
            IMediator mediator,
            CancellationToken cancellationToken) =>
        {
            var query = new GetUserByIdQuery(userId);

            Result<UserResponse> result = await mediator.Send(query, cancellationToken);
            return result.Match(Results.Ok, ApiResponse.Problem);
        })
        .WithTags(Tags.Users)
        .HasApiVersion(1, 0)
        .RequireAuthorization();
 
    }
}
